//
//  WaitingToPayViewController.m
//  MagazineShangejie
//
//  Created by wen on 15/11/12.
//  Copyright © 2015年 CnbizMedia. All rights reserved.
//

#import "PayTheVIPViewController.h"
#import "WaitingToPayViewController.h"
#import "Util.h"
@interface WaitingToPayViewController (){
    
    NSMutableDictionary *orderDic;
    NSString     *vipName;
    NSString     *vipFirst;
    NSString     *vipLast;
}
@property (weak, nonatomic) IBOutlet UILabel *checkLabel;
@property (weak, nonatomic) IBOutlet UILabel *OrderIDLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UILabel *userName;
@property (weak, nonatomic) IBOutlet UILabel *phoneNumber;
@property (weak, nonatomic) IBOutlet UIButton *checkButton;

@end

@implementation WaitingToPayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    orderDic = [[NSMutableDictionary alloc] init];

    //没通过审核
    if ([[UserDefaults objectForKey:@"trial"] integerValue] == 1) {
        _checkButton.userInteractionEnabled = NO;
        _checkButton.backgroundColor = [UIColor lightGrayColor];
        vipFirst = @"您的";
        vipLast  = @"抱歉没有审核通过，请您稍后再试！";
    }
    
    //等待审核
    else{
        vipFirst = @"您的";
        vipLast  = @"申请已经提交成功，我们的工作人员会尽快和您联系并核实确认您的相关信息，申请审核通过以后才可以继续完成订单支付，请稍候，我们正在为您联系VIP客服！";
    }
    
    
    if ([[UserDefaults objectForKey:@"VIP"] isEqualToString:@"VIP"]) {
                    vipName = @"铂金用户";
        NSDictionary *Goodaaaccc = [UserDefaults objectForKey:@"Goodaaaccc"];
        NSDictionary *Goodorder = [UserDefaults objectForKey:@"Goodorder"];
        [orderDic addEntriesFromDictionary:Goodaaaccc];
        
        NSLog(@"--orderDic-- %@",orderDic);
        //        _vipMoney.text = @"￥6000.00";
    }
    else{
                    vipName = @"钻石用户";
        
        NSDictionary *DiamondOrder = [UserDefaults objectForKey:@"DiamondOrder"];
        NSDictionary *Diamondaaaccc = [UserDefaults objectForKey:@"Diamondaaaccc"];
        [orderDic addEntriesFromDictionary:Diamondaaaccc];
        
        NSLog(@"++orderDic++ %@",orderDic);
        //        _vipMoney.text = @"￥20000.00";
    }
    
    NSDictionary *Goodaaaccc = [UserDefaults objectForKey:@"Goodaaaccc"];
    NSLog(@"Goodaaaccc == %@",Goodaaaccc);
    NSDictionary *Diamondaaaccc = [UserDefaults objectForKey:@"Diamondaaaccc"];
    NSLog(@"Diamondaaaccc == %@",Diamondaaaccc);
    
    
    
    NSDictionary *Goodorder = [UserDefaults objectForKey:@"Goodorder"];
    NSDictionary *DiamondOrder = [UserDefaults objectForKey:@"DiamondOrder"];
    NSLog(@"Goodorder _-+%@",Goodorder);
    NSLog(@"DiamondOrder _-+%@",DiamondOrder);
    
    [self showTheCheck];
}

- (void)showTheCheck{

    
    
   
    NSString* str = [NSString stringWithFormat:@"您的%@ %@", vipName,vipLast];
    NSMutableAttributedString* aStr = [[NSMutableAttributedString alloc] initWithString:str];
    
    [aStr addAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                         [UIFont systemFontOfSize:10],
                         NSFontAttributeName,
                         [UIColor redColor],
                         NSForegroundColorAttributeName,
                         nil ]
                  range:[str rangeOfString:vipName]];
    
    [aStr addAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                         [UIFont systemFontOfSize:10],
                         NSFontAttributeName,
                         [UIColor blackColor],
                         NSForegroundColorAttributeName,
                         nil ]
                  range:[str rangeOfString:vipLast]];
    
    _checkLabel.attributedText = aStr;
 
    _OrderIDLabel.text = [orderDic objectForKey:@"trade_sn"];
    
    NSDateFormatter * formatter = [[NSDateFormatter alloc ] init];
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm"];
    
     NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[[orderDic objectForKey:@"addtime"] integerValue]];
       NSLog(@"1296035591  = %@",confromTimesp);
       NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];
     NSLog(@"confromTimespStr =  %@",confromTimespStr);
    _timeLabel.text = confromTimespStr;
    _userName.text = [orderDic objectForKey:@"username"];
    _phoneNumber.text = [orderDic objectForKey:@"telephone"];
 
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)gotoSomeWhere:(id)sender {
    
    UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    PayTheVIPViewController*web=[story instantiateViewControllerWithIdentifier:@"PayTheVIPViewController"];
    
    [self.navigationController pushViewController:web animated:YES];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
